package com.sl.hx.shop.ui.collect.adapter;

import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.DynamicDrawableSpan;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sl.hx.shop.R;
import com.sl.hx.shop.bean.CollectGoodsBean;
import com.sl.hx.shop.bean.CollectList;

import java.util.List;

public class CollectGoodsAdapter extends BaseQuickAdapter<CollectList,BaseViewHolder> {


    public CollectGoodsAdapter(@Nullable List<CollectList> data) {
        super(R.layout.item_collectgoods, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final CollectList item) {
        if (item!=null) {
            helper.setText(R.id.GoodsName, item.getTitle())
                    .setText(R.id.GoodsPrice, item.getZk_final_price())
                    .setText(R.id.tb_price, "淘宝价格￥" + item.getReserve_price())
                    .setText(R.id.volume, item.getVolume() + "人已付款");

            ImageView image = helper.getView(R.id.icon);
            Glide.with(mContext).load(item.getPict_url()).into(image);

            //标题前加淘宝图片
            TextView title = helper.getView(R.id.GoodsName);
            SpannableStringBuilder stringBuilder = new SpannableStringBuilder("  " + item.getTitle());
            DynamicDrawableSpan ab = new DynamicDrawableSpan() {
                @Override
                public Drawable getDrawable() {
                    if (item.getUser_type()==0) {
                        Drawable drawable = mContext.getResources().getDrawable(R.drawable.taobao);
                        drawable.setBounds(0, 0, 65, 36);
                        return drawable;
                    }else {
                        Drawable drawable = mContext.getResources().getDrawable(R.drawable.tianmao);
                        drawable.setBounds(0, 0, 65, 36);
                        return drawable;
                    }
                }
            };
            stringBuilder.setSpan(ab, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            title.setText(stringBuilder);

        }
    }

}
